﻿define(
["jquery","templUtil"], 
function(a, b) {
    
    $.fn.commNavTabs = function () {
        /* common nav-tabs */
        // comm-tabs, comm-tabs-head, head-item
        // comm-tabs-body, comm-tabs-body, body-item
        this.each(function () {
            var headItems = $(this).find(".head-item");
            var bodyItems = $(this).find(".body-item");
            headItems.on("click", function () {
                var idx = $(this).index();
                var tmpBodyItem = bodyItems.eq(idx);
                $(this).addClass("current").siblings().removeClass("current");
                tmpBodyItem.show().siblings().hide();
            });
        });
    };
    
    // comm-paging
    if ($("<div>").paging) {
        
        $(".comm-paging").paging(100, {
            format : "[< nncnn >]",
            perpage : 7,
            page : 1,
            onSelect : function (page) {
                // $.ajax(), DOTO
                console.log("page: " + page);
            },
            onFormat : function (type) {
                switch (type) {
                case 'block': // n and c
                    if (!this.active) {
                        return "<a href='#' class='disable'>" + this.value + "</a>";
                    } else if (this.value == this.page) {
                        return "<a href='#' class='current'>" + this.value + "</a>";
                    } else {
                        return "<a href='#'>" + this.value + "</a>";
                    }
                    
                    return '<a href="#">' + this.value + '</a>';
                    
                case 'next': // >
                    if (this.page == this.pages) {
                        return "<a href='#' class='disable'>下一页</a>";
                    }
                    return '<a href="#">下一页</a>';
                case 'prev': // <
                    if (this.page == 1) {
                        return "<a href='#' class='disable'>上一页</a>";
                    }
                    return '<a href="#">上一页</a>';
                case 'first': // [
                    if (this.page == 1) {
                        return "<a href='#' class='disable'>首页</a>";
                    }
                    return '<a href="#">首页</a>';
                case 'last': // ]
                    if (this.page == this.pages) {
                        return "<a href='#' class='disable'>尾页</a>";
                    }
                    return '<a href="#">尾页</a>';
                }
                return "";
            }
        });
    }
    

     
    var commTemplUtil = b;
    
    if (COMM_DATA.topObj.loginFlag == '0') {
        commTemplUtil.setTempl("top_test", COMM_DATA.topObj, "login");
    } else {
        commTemplUtil.setTempl("top_test", COMM_DATA.topObj, "loginDone");
    }
    
    commTemplUtil.setTempl("web_logo_search", COMM_DATA.searchObj, "search");
    commTemplUtil.setTempl("comm_nav", COMM_DATA.mainNavObj, "headNav");
    commTemplUtil.addTempl("bottom_main", {}, "bottomMenu");
    commTemplUtil.addTempl("leftmenuitems", COMM_DATA.leftNavObj, "leftMenu");
    commTemplUtil.setTempl("foot_nav", COMM_DATA.footNavObj, "footNav");
    
   
    
});